/*
 * COPYRIGHT. ShenZhen iByte Technology Co., Ltd. 2018.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen iByte Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * Dec 3, 2018    Li.shangzhi         Create the class
 */
package com.github.icloud.elasticsearch.api.aggregations;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.junit.Test;
import com.github.icloud.elasticsearch.ElasticsearchClientBase;
/**
 * @FileName StructuringAggregations.java
 * @Description: 
 *
 * @Date Dec 3, 2018 5:51:28 PM
 * @author Li.shangzhi
 * @version 1.0
 */
public class StructuringAggregations extends ElasticsearchClientBase{

	@Test
	public void iEsStructuringAggregations() throws Exception{
		SearchResponse sr = client.prepareSearch()
				.addAggregation(
						AggregationBuilders.terms("user").field("ibyte")  
						.subAggregation(AggregationBuilders.dateHistogram("by_year")
								.field("postDate")
								.dateHistogramInterval(DateHistogramInterval.YEAR)
//								.subAggregation(AggregationBuilders.avg("avg_children").field("children"))
								)
						)
						.execute().actionGet();

		println(sr);
	}
}
